#include "uohashtable.h"

int hashLocate(char* newArray){
	int index=1,i=0;
	while(newArray[i]!='\0'){
		index=index*(int)newArray[i];
		i++;
		if(index>=HASHSIZE)index=index%HASHSIZE;
	}
	while(elements[index].tag&&strcmp(elements[index].name,newArray)){
		index=index+HASHSKIP;
		if(index>=HASHSIZE)index=index%HASHSIZE;
	}
	return index;
}

int hashGet(char* newArray){
	int index,i=0;
	index=hashLocate(newArray);
	if(!elements[index].tag)return -1;
	else return index;
}

int hashPut(char* newArray,int type,int* size,int dimension){
	int index,i=0;
	index=hashLocate(newArray);
	if(elements[index].tag&&strcmp(elements[index].name,newArray)){
		return -1;
	}else{
		elements[index].tag=1;
		strcpy(elements[index].name,newArray);
		elements[index].type=type;
		for(i=0;i<dimension;i++)
			elements[index].size[i]=size[i];
		elements[index].dim=dimension;
	}
	return index;
}
